<template>
  <div id="app">
    <h1>Vue3 ToDoList</h1>
    <a href="https://gitee.com/dmsllll/todolist11.git" target="_blank">查看代码仓库</a>
    
    <div class="todo-container">
      <TodoForm @onAdd="addTask" />
      <TodoList :tasks="tasks" @deleteTask="deleteTask" />
      
      <div class="stats">
        <p>总任务: {{ tasks.length }} | 已完成: {{ completedCount }}</p>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue';
import TodoForm from './components/TodoForm.vue';
import TodoList from './components/TodoList.vue';

// 初始化任务列表
const tasks = ref([
  { id: 1, text: '学习Vue3', completed: false },
  { id: 2, text: '提交作业', completed: true },
  { id: 3, text: '完成vue3', completed: false }
]);

// 计算已完成任务数量
const completedCount = computed(() => {
  return tasks.value.filter(task => task.completed).length;
});

// 添加新任务
const addTask = (text) => {
  tasks.value.push({
    id: Date.now(), // 使用时间戳作为唯一ID
    text,
    completed: false
  });
};

// 删除任务
const deleteTask = (id) => {
  tasks.value = tasks.value.filter(task => task.id !== id);
};
</script>

<style scoped>
#app {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
  font-family: Arial, sans-serif;
}

h1 {
  text-align: center;
  color: #333;
}

a {
  display: block;
  text-align: center;
  margin-bottom: 20px;
  color: #007bff;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.todo-container {
  background-color: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.stats {
  margin-top: 20px;
  text-align: center;
  color: #666;
  font-size: 14px;
}
</style>